package edu.sctu.wulixia.month6.day20150619;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by user05 on 2015/6/19.
 */
public class HttpUrl {
    public void getHttpUrl(String path){
        int count ;
        String param = "\"rec_id=145\"&\"goods_id=14092\"";

        try {
            URL url = new URL(path);
            byte[] buffer = new byte[1024];

            try {
                URLConnection urlConnection = url.openConnection();
                urlConnection.setDoOutput(true);
                urlConnection.connect();

                OutputStream outputStream = urlConnection.getOutputStream();
                outputStream.write(param.getBytes());
                outputStream.flush();

                System.out.println(urlConnection.getContentType()+":"+
                urlConnection.getContentEncoding());

                InputStream inputStream = urlConnection.getInputStream();

                while ((count = inputStream.read(buffer)) != -1){
                    System.out.println(new String(buffer,0,count,"utf-8"));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }


}
